module FRM_TOP (
   RESET,
   TCLK_155M,
   RCLK_155M,
   GLB_SFI2SFI_LOOP,      // global loopback control signal
   GLB_CORE2CORE_LOOP,
  // interface to global CPU interface
   CPU_CLK,
   CPU_CS,
   CPU_WREN,
   CPU_ADDR,
   CPU_WDATA,
   CPU_RDATA,
  // interface to SFI interface
   SFI4_RCLK,
   SFI4_RDATA,
   SFI4_TCLK,
   SFI4_TDATA,
  //
   OH2FRM_TDATA,
   OH2FRM_FCNT8,
   OH2FRM_FCNT270,
   OH2FRM_FCNT9,
  //
   FRM2OH_LOF,
   FRM2OH_OOF,
   FRM2OH_FCNT8,
   FRM2OH_FCNT270,
   FRM2OH_FCNT9,
   FRM2OH_RDATA,
   FRM2OH_B1ERROR_CNT
   );

input                 RESET;
input                 TCLK_155M;
input                 RCLK_155M;
input                 GLB_SFI2SFI_LOOP;
input                 GLB_CORE2CORE_LOOP;

input                 CPU_CLK;
input                 CPU_CS;
input                 CPU_WREN;
input[7:0]            CPU_ADDR;
input[15:0]           CPU_WDATA;
output[15:0]          CPU_RDATA;

input                 SFI4_RCLK;
input[63:0]           SFI4_RDATA;
input                 SFI4_TCLK;
output[63:0]          SFI4_TDATA;

input[63:0]           OH2FRM_TDATA;
input[2:0]            OH2FRM_FCNT8;
input[8:0]            OH2FRM_FCNT270;
input[3:0]            OH2FRM_FCNT9;

output                FRM2OH_LOF;
output                FRM2OH_OOF;
output[2:0]           FRM2OH_FCNT8;
output[8:0]           FRM2OH_FCNT270;
output[3:0]           FRM2OH_FCNT9;
output[63:0]          FRM2OH_RDATA;
output[3:0]           FRM2OH_B1ERROR_CNT;

wire[63:0]            CORE2LOOP_TDATA;
wire[63:0]            LOOP2CORE_RDATA;

wire[15:0]            MPI_PAR_KEEP;
wire                  MPI_DSCRM_EN;
wire                  MPI_SRCM_EN;
wire                  MPI_LOS2AIS_EN;
wire                  MPI_LOC2AIS_EN;
wire                  MPI_LOF2AIS_EN;
wire                  MPI_OOF2AIS_EN;
wire                  MPI_LOS_ALM;
wire                  MPI_LOC_ALM;
wire                  MPI_LOF_ALM;
wire                  MPI_OOF_ALM;

wire                  MATCH2DSCRM_LOF;
wire                  MATCH2DSCRM_OOF;
wire[2:0]             MATCH2DSCRM_FCNT8;
wire[8:0]             MATCH2DSCRM_FCNT270;
wire[3:0]             MATCH2DSCRM_FCNT9;
wire[63:0]            MATCH2DSCRM_DATA;

SFI_LOOP_CONTROL INST_SFI_LOOP_CONTROL(
   .RESET             ( RESET ),
   .SFI4_RCLK         ( SFI4_RCLK ),
   .SFI4_RDATA        ( SFI4_RDATA[63:0] ),
   .SFI4_TCLK         ( SFI4_TCLK ),
   .SFI4_TDATA        ( SFI4_TDATA[63:0] ),
   .CORE_RCLK         ( RCLK_155M ),
   .CORE_RDATA        ( LOOP2CORE_RDATA[63:0] ),
   .CORE_TCLK         ( TCLK_155M ),
   .CORE_TDATA        ( CORE2LOOP_TDATA[63:0] ),

   .MPI_SFI2SFI_LOOP  ( GLB_SFI2SFI_LOOP ),     // loop SFI4 Received data to transmit data
   .MPI_CORE2CORE_LOOP( GLB_CORE2CORE_LOOP ),   // loop core logic transmit data to received data
   .MPI_FIFO_CLEAR    ( ),
   .MPI_ERROR_CLEAR   ( ),
   .MPI_FIFO_FULL     ( ),
   .MPI_FIFO_EMPTY    ( )
   );

FRM_SCRM              INST_FRM_SCRM(
   .RESET             ( RESET ),
   .TCLK_155M         ( TCLK_155M ),

   .DBIN_TDATA        ( OH2FRM_TDATA[63:0] ),
   .DBIN_FCNT8        ( OH2FRM_FCNT8[2:0] ),
   .DBIN_FCNT270      ( OH2FRM_FCNT270[8:0] ),
   .DBIN_FCNT9        ( OH2FRM_FCNT9[3:0] ),
   .MPI_SRCM_EN       ( MPI_SRCM_EN ),

   .DBOUT_TDATA       ( CORE2LOOP_TDATA[63:0] )
   );


FRM_FAS_MATCH         INST_FRM_FAS_MATCH(
   .RESET             ( RESET ),

   .RCLK_155M         ( RCLK_155M ),
   .SFI4_RDATA        ( LOOP2CORE_RDATA[63:0] ),
   .MPI_PAR_KEEP      ( MPI_PAR_KEEP[7:0] ),

   .FAS_LOF           ( MATCH2DSCRM_LOF ),
   .FAS_OOF           ( MATCH2DSCRM_OOF ),
   .FAS_MATCH_FCNT8   ( MATCH2DSCRM_FCNT8[2:0] ),
   .FAS_MATCH_FCNT270 ( MATCH2DSCRM_FCNT270[8:0] ),
   .FAS_MATCH_FCNT9   ( MATCH2DSCRM_FCNT9[3:0] ),
   .FAS_MATCH_DATA    ( MATCH2DSCRM_DATA[63:0] )
   );

 FRM_DSCRM            INST_FRM_DSCRM(
   .RESET             ( RESET ),
   .RCLK_155M         ( RCLK_155M ),
   .MPI_DSCRM_EN      ( MPI_DSCRM_EN ),

   .FAS_LOF           ( MATCH2DSCRM_LOF ),
   .FAS_OOF           ( MATCH2DSCRM_OOF ),
   .FAS_FCNT8         ( MATCH2DSCRM_FCNT8[2:0] ),
   .FAS_FCNT270       ( MATCH2DSCRM_FCNT270[8:0] ),
   .FAS_FCNT9         ( MATCH2DSCRM_FCNT9[3:0] ),
   .FAS_DATA          ( MATCH2DSCRM_DATA[63:0] ),

   .DSCRM_LOF         ( FRM2OH_LOF ),
   .DSCRM_OOF         ( FRM2OH_OOF ),
   .DSCRM_FCNT8       ( FRM2OH_FCNT8[2:0] ),
   .DSCRM_FCNT270     ( FRM2OH_FCNT270[8:0] ),
   .DSCRM_FCNT9       ( FRM2OH_FCNT9[3:0] ),
   .DSCRM_DATA        ( FRM2OH_RDATA[63:0] ),
   .DSCRM_B1ERROR_CNT ( FRM2OH_B1ERROR_CNT[3:0] )
   );

  assign  MPI_LOF_ALM = FRM2OH_LOF;
  assign  MPI_OOF_ALM = FRM2OH_OOF;
FRM_MPI               INST_FRM_MPI(
   .RESET             ( RESET ),

   .CPU_CLK           ( CPU_CLK ),
   .CPU_CS            ( CPU_CS ),
   .CPU_WREN          ( CPU_WREN ),
   .CPU_ADDR          ( CPU_ADDR[7:0] ),
   .CPU_WDATA         ( CPU_WDATA[15:0] ),
   .CPU_RDATA         ( CPU_RDATA[15:0] ),

  // 
   .MPI_PAR_KEEP      ( MPI_PAR_KEEP[15:0] ),
  //
   .MPI_SRCM_EN       ( MPI_SRCM_EN ),
   .MPI_DSCRM_EN      ( MPI_DSCRM_EN ),
   .MPI_LOS2AIS_EN    ( MPI_LOS2AIS_EN ),
   .MPI_LOC2AIS_EN    ( MPI_LOC2AIS_EN ),
   .MPI_LOF2AIS_EN    ( MPI_LOF2AIS_EN ),
   .MPI_OOF2AIS_EN    ( MPI_OOF2AIS_EN ),
   .MPI_LOS_ALM       ( MPI_LOS_ALM ),
   .MPI_LOC_ALM       ( MPI_LOC_ALM ),
   .MPI_LOF_ALM       ( MPI_LOF_ALM ),
   .MPI_OOF_ALM       ( MPI_OOF_ALM )
   );

endmodule 
